import { ref } from "vue";

export function useColumns(info) {
	const productList = ref([
		{
			did: 1,
			materialId: null,
			planNum: null,
			realNum: null,
			batchNo: null,
			produceDate: null,
		}
	]);
	if(info.title === '修改') {
		if(info.materialList.length > 0) {
			productList.value = info.materialList
		}
	}
	const vehicleColumns: TableColumnList = [
		{
			label: "物料",
			prop: "materialId",
			slot: "material"
		},
    
		{
			label: "计划数量",
			prop: "planNum",
			cellRenderer: ({ row }) => <el-input-number type="number" precision={0} min={1} v-model={row.planNum}  controls-position="right" placeholder="请输入计划数量" style="width: 100%"/>

		},
		{
			label: "实际数量",
			prop: "realNum",
			cellRenderer: ({ row }) => <el-input-number type="number" precision={0} min={1} v-model={row.realNum}  controls-position="right" placeholder="请输入实际数量" style="width: 100%"/>
		
		},
		{
			label: "批次号",
			prop: "batchNo",
			cellRenderer: ({ row }) => <el-input v-model={row.batchNo}  placeholder="请输入批次号"/>
		},
		{
			label: "生产日期",
			prop: "produceDate",
			cellRenderer: ({ row }) => <el-date-picker v-model={row.produceDate} type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" placeholder="请选择生产日期"/>
		},
		{
			label: "操作",
			fixed: "right",
			width: 80,
			slot: "operation"
		}
	];
	function vehicleOnAdd() {
		productList.value.push({
			did: productList.value.length + 1,
			materialId: null,
			planNum: null,
			realNum: null,
			batchNo: null,
			produceDate: null,
		});
	}

	function vehicleOnDel(index) {
		productList.value.splice(index, 1);
	}

	return {
		vehicleColumns,
		productList,
		vehicleOnAdd,
		vehicleOnDel
	};
}
